package com.jing.intellij.apama

import com.intellij.ide.projectView.TreeStructureProvider
import com.intellij.ide.projectView.ViewSettings
import com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode
import com.intellij.ide.util.treeView.AbstractTreeNode

/**
 * IntelliJ默认将工程记为ProjectViewProjectNode, 包含的子节点:一个ExternalLibrariesNode, 多个PsiFileNode, 多个PsiDirectoryNode
 */
class ApamaTreeStructureProvider: TreeStructureProvider {
    override fun modify(
        parent: AbstractTreeNode<*>,
        children: MutableCollection<AbstractTreeNode<*>>,
        settings: ViewSettings?
    ): MutableCollection<AbstractTreeNode<*>> {
        val project = parent.project
        if (project?.isDisposed == true) {
            return children;
        }
        if (parent is PsiDirectoryNode) {
            val projectPath = parent.project?.basePath;
            val dirPath = parent.virtualFile?.path
            if (projectPath == dirPath) {
                //工程根目录, 开始处理
                val result:MutableCollection<AbstractTreeNode<*>> = mutableListOf()
                for (node in children) {
                    if (node is PsiDirectoryNode)
                        if (".idea" != node.virtualFile?.name) {
                            //不显示.idea目录
                            result.add(node)
                        }
                }
                if (!result.isEmpty()) {
                    return result;
                }
            }
        }
        return children;
    }




}